#include <stdio.h>

/* ASSUMPTION: Atleast one positive number exists */
int main()
{
	int a[] = { -1, 2, -300, -100, -3, -4, -9, -19, -24, -1, -23, -1, -28, -38, -16, -35, -37, 2};

	int maxstart = 0, maxend = 0, maxsum = -1, cursum, curstart;
	
	int i = 0;

	int N = 18;

	while (i < N) {

		curstart = i;
		cursum = 0;

		while (i < N && a[i] >= 0) {
			cursum += a[i];

			i++;
		}

		if (cursum > maxsum) {
			printf("Max value changed. New start: %d New end: %d\n", curstart, i-1);
			maxstart = curstart;
			maxend = i-1;
			maxsum = cursum;
		}

		i++;
	}

	printf("start: %d end: %d sum: %d\n", maxstart, maxend, maxsum);
	for (i=maxstart; i <= maxend; i++)
		printf("[%d] ", a[i]);

	return 0;
}
